import smtplib
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header

# 邮件发送者和接收者
sender = 'wyguolai@163.com'
receivers = ["wyguolai@163.com"]

# 邮件内容
message = MIMEMultipart()
message.attach(MIMEText('邮件内容', 'plain', 'utf-8'))
message['From'] = Header('发件人名称', 'utf-8')
message['To'] = Header('收件人名称', 'utf-8')
message['Subject'] = Header('邮件主题', 'utf-8')

# SMTP 邮件服务器信息
smtp_server = 'smtp.163.com'
smtp_port = 25  # 邮箱默认不用配置
smtp_username = 'wyguolai@163.com'
smtp_password = 'ARUYHGWGTBPBAQEC'



# 附件
file_path = '计算器.html'
with open(file_path, 'rb') as f:
    attachment = MIMEApplication(f.read(),"base64")
    attachment.add_header('Content-Disposition', 'attachment', filename='a.py')
    message.attach(attachment)

#RLAKRRVTPJVYWCZY
# 发送邮件
try:
    smtp_obj = smtplib.SMTP(smtp_server) # 端口默认不用配置，若需要配置则加上面的port端口
    smtp_obj.login(smtp_username, smtp_password)
    smtp_obj.sendmail(sender, receivers, message.as_string())
    print('邮件发送成功')
except smtplib.SMTPException as e:
    print('邮件发送失败', e)